package com.itheima.aliyun;


import com.aliyun.ocr_api20210707.Client;
import com.aliyun.ocr_api20210707.models.RecognizeGeneralRequest;
import com.aliyun.ocr_api20210707.models.RecognizeGeneralResponse;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.models.RuntimeOptions;

import java.io.FileInputStream;

/**
 * OCR 快速入门
 */
public class OcrQuickStart {

    public static void main(String[] args) throws Exception {
        // 1 创建Config实例并初始化
        Config authConfig = new Config();
        authConfig.accessKeyId = "LTAI5t8V33L3pg9K5sf4BRWp";
        authConfig.accessKeySecret = "TkdQCSUlxfayu9QIO9p9nAJFfer2Jx";
        // 文字识别的服务入口
        authConfig.endpoint = "ocr-api.cn-hangzhou.aliyuncs.com";

        Client client = new Client(authConfig);

        // 2 创建RuntimeObject实例并设置运行参数
        RuntimeOptions runtime = new RuntimeOptions();
        // 是否开启失败重试
        runtime.autoretry = true;
        // 最大重试次数
        runtime.maxAttempts = 5;

        // 3 创建API请求并设置参数
        RecognizeGeneralRequest request = new RecognizeGeneralRequest();
        //request.setUrl("https://img.alicdn.com/imgextra/i3/O1CN01BJBQ6i1tl1fq1yOrD_!!6000000005941-2-tps-805-655.png");
        //request.setUrl("http://192.168.75.120:9000/leadnews/2022/06/18/1.png");
        request.setBody(new FileInputStream("E:\\黑马每日资料\\黑马头条-140\\day04-自媒体文章审核\\资料\\1.png"));

        // 4 发起请求并处理应答或异常
        RecognizeGeneralResponse response = client.recognizeGeneralWithOptions(request, runtime);
        System.out.println(response.getBody().getData());
    }

}